#pragma GCC optimize(2)
#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
#include <bitset>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int N=2e5+10;
ll dist[N];
int p[N];
int find(int x)
{
	if(p[x]!=x)
	{
		int t = find(p[x]);
		dist[x]=dist[x]+dist[p[x]];
		p[x]=t;
	}
	return p[x];
}
void init(int n)
{
	for(int i=0;i<=n;i++)
	{
		p[i]=i;
		dist[i]=0;
	}
}
void solve()
{
	int n,m;
	cin>>n>>m;
	init(n);
	int f=0;
	while(m--)
	{
		int a,b,d;
		cin>>a>>b>>d;
		int fa=find(a);
		int fb=find(b);
//		cout<<fa<<' '<<fb<<endl;
		if(f) continue;
		if(fa==fb)
		{
//			cout<<dist[a]<<' '<<dist[b]<<endl;
			if(dist[a]-dist[b]!=d) f=1;
		}
		else
		{
			dist[fa]=dist[b]+d-dist[a];
//			cout<<dist[fa]<<endl;
			p[fa]=fb;
		}
	}
	if(f) cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
}
int main()
{
	IOS;
	int __t=1;
	cin>>__t;

	while(__t--)
	{
		solve();
	}

	return 0;
}

